#ifndef __DSTH_ACCEPTOR_H__
#define __DSTH_ACCEPTOR_H__

#include "Socket.h"
#include "Channel.h"

namespace dsth {

class EventLoop;
class Acceptor {
public:
    typedef Delegate<void (int, const InetSocketAddress&)> AcceptHandler;
    Acceptor(EventLoop* loop, const InetSocketAddress& addr);
    ~Acceptor(void);
    void Listen();
    void SetAcceptHandler(const AcceptHandler& handler) { accept_handler_ = handler; }
private:
    // Can't invoke copy constructor or assignment operator
    Acceptor(const Acceptor&);
    void operator=(const Acceptor&);

    void OnReadEnabled(Timestamp recv_time);

    Socket accept_socket_;
    EventLoop* loop_;
    Channel channel_;
    AcceptHandler accept_handler_;
};

} // namespace
#endif // __DSTH_ACCEPTOR_H__
